<template>
	<comRoot :useRootSence="'newerborn'" @execAfterToken="getLastDataFun">
		<template #page>
			<image
				v-if="commonConfigs && commonConfigs.domainFrontFileLink"
				:src="`${commonConfigs.domainFrontFileLink}/files/images/page-bg.png`" 
				class="bg"
			></image>
			
			<view class="newer-born-zone">
				
				<comDetailNavigateBack style="z-index: 100;position: absolute;"/>
				
				<view class="newer-content relative flex flex-direction-column">
					<view class="newer-content-bg relative">
						<image class="bg" :src="rewardPoolBanner" mode="aspectFill" />
					</view>

					<view class="newer-content-box fixed">
						<view class="countdown-time-view relative flex flex-direction-column">
							<view class="countdown-time-detail flex flex-align-items-center relative">
								<!-- <image class="bg"
								v-if="commonConfigs && commonConfigs.domainFrontFileLink"
								:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/countdown-time-bg.png`" /> -->
								
								<view class="countdown-time-txt relative">活动倒计时:</view>
								<view class="countdown-time-nums relative">{{ countDownTimeTxt }}</view>
							</view>
							
							<!-- type 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠 -->
							<image class="award-entry-icon absolute" 
							 @click="getPoolRecordFun"
							 v-if="commonConfigs && commonConfigs.domainFrontFileLink && newerPoolWelfareList[currentIdLever] && newerPoolWelfareList[currentIdLever].type !== 1"
							 :src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/record-list-btn.png`"
							 mode=""></image>
						</view>
						
						<view class="com-bullet-chat relative">
							<!-- <image class="bg" 
							style="width: 750rpx;height: 275rpx;"
							v-if="commonConfigs && commonConfigs.domainFrontFileLink"
							:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/bullet-chat-bg.png`" /> -->
							
							<!-- <comBulletChat :key="timeLenStr" :bulletChatRecordData="bulletChatRecordData" @getLastBulletChatFun="getLastBulletChatFun" 
							useSence="newerborn"
							/> -->
						</view>
						
						<view class="pool-type-content flex relative">
							<image class="bg" 
							v-if="commonConfigs && commonConfigs.domainFrontFileLink"
							:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/detail-content.png`" />
							
							<!-- 左边切换项目滚动区域 -->
							<view class="pool-type-title flex flex-direction-column relative flex-align-items-center" :style="{'background-image': `url(${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/left-content_bg.png.png)`}">
								<!-- <image class="bg" style="z-index: 9999;"
								v-if="commonConfigs && commonConfigs.domainFrontFileLink"
								:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/left-content_bg.png`" /> -->
								<view v-for="(item, index) in newerPoolWelfareList" :key="index" class="pool-type-info relative flex-justify-content-center flex-direction-column">
									<view :class="['pool-type-list', 'font-hanserif-bold', 'flex', 'flex-all-center', 'flex-direction-column', 'relative', currentIdLever === index ? 'pool-type-info-active': '',]" @click="tabPoolTypeFun(item, index)">
										<image class="bg"
											style="width: 211rpx; height: 92rpx;"
											v-if="commonConfigs && commonConfigs.domainFrontFileLink && currentIdLever === index"
											:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/level-bg-active.png`" />
										<image class="bg"
											v-else
											style="width: 211rpx; height: 92rpx;"
											:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/level-bg.png`" />
										
										<image 
											style="left: 4rpx;top: 0rpx;width: 72rpx;height: 18rpx;"
											v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.type === 1 && item.red_hit" class="absolute" 
											:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/novice-receive.png`" mode=""></image>
										
										<image 
											style="left: 4rpx;top: 0rpx;width: 72rpx;height: 18rpx;"
											v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.type === 4 && item.red_hit" class="absolute" 
											:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/novice-free.png`" mode=""></image>
										
										<!-- type 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠 -->
										<view :class="['info-maintitle', 'relative']">{{ getfilterValueArrayFun(poolTypeData, 'type', item.type).mainTitle }}</view>
										
										<view v-if="item.is_start" :class="['info-subtitle', 'relative']">{{ item.title || getfilterValueArrayFun(poolTypeData, 'type', item.type).subTitle }}</view>
										
										<view v-if="!item.is_start" :class="['info-dates',  'relative',  'flex',  'flex-all-center', currentIdLever === index ? 'item-time-active': '',]">
											<view class="info-dates-txt">
												{{ item.start_time }}开启
											</view>
										</view>
									</view>
									
								</view>
							</view>
							
							<view class="pool-type-detail flex-full relative">
								<view class="pool-type-detail-box relative font-hanserif-bold flex flex-align-items-end">
									<image class="bg"
									style="width: 100%; height: 52rpx;top: 20rpx;left: 20rpx;"
									:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/list-right-title-bg.png`" />
									
									<!-- type 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠 -->
									<view :class="['text-nowrap', 'detail-box-maintitle', 'relative',]">{{ newerPoolWelfareList[currentIdLever] ? getfilterValueArrayFun(poolTypeData, 'type', newerPoolWelfareList[currentIdLever].type).mainTitle : '-' }}</view>
									<view :class="['text-nowrap', 'detail-box-subtitle', 'relative',]">{{ newerPoolWelfareList[currentIdLever] ? getfilterValueArrayFun(poolTypeData, 'type', newerPoolWelfareList[currentIdLever].type).subTitle : '-' }}</view>
									<view :class="['text-nowrap', 'detail-box-tiptitle', 'relative',]" v-if="newerPoolWelfareList[currentIdLever] && newerPoolWelfareList[currentIdLever].type === 1">(当前优惠券可免费领取)</view>
									<view v-else class="flex-full relative" style="top: 16rpx;">
										<view :class="['detail-box-tiptitle', 'relative', 'truncate']" v-if="showNoticeTxtFun('(获得概率为初始参考概率，实际概率随着抽赏进度动态变化)', 20)" style="text-align: center;">
											<uni-notice-bar
												class="uni-notice-bar"
												color="#63FFF7"
												background-color="transparent"
												:scrollable="true"
												:single="true"
												:text="showNoticeTxtFun('(获得概率为初始参考概率,实际概率随着抽赏进度动态变化)', 20)"
												:speed="54"
											></uni-notice-bar>
										</view>
										<view :class="['detail-box-tiptitle', 'relative', 'truncate']" v-else>
											(获得概率为初始参考概率,实际概率随着抽赏进度动态变化)
										</view>
									</view>
								</view>
								
								<view class="detail-box-info relative font-hanserif-bold flex flex-direction-column flex-align-items-center">
									
									<view class="detail-box-info-content relative" v-if="newerPoolWelfareList[currentIdLever] && newerPoolWelfareList[currentIdLever].type === 1"
										v-for="(item, index) in newerCouponData" :key="index">
										<image class="bg" :src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/items-detail-coupon-bg.png`" />
									 
										<view class="info-detail-title relative flex-all-center">
											<view class="info-detail-title-txt absolute ">
												<image class="bg" style="height: 48rpx;min-width: 262rpx;"
												:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/items-detail-coupon-desc-bg.png`" />
												<view class="relative">{{ item.desc }}</view>
											</view>
										</view>
										
										<view class="info-detail-coupons flex flex-direction-column flex-all-center relative">
											<view class="detail-coupons-box flex flex-full">
												
												<view class="coupons-box-view relative" v-for="(couponItem, couponIndex) in item.coupon_lists" :key="couponIndex">
													<view class="coupons-box-img flex flex-all-center relative">
														<image class="coupons-box-img-cover relative" :src="couponItem.mini_cover" mode="heightFix"></image> 
													</view>
													
													<view class="coupons-bar-title" v-if="showNoticeTxtFun(couponItem.subtitile, 5)" style="text-align: center;">
														<uni-notice-bar
															class="uni-notice-bar"
															color="#FFFF"
															background-color="transparent"
															:scrollable="true"
															:single="true"
															:text="showNoticeTxtFun(couponItem.subtitile, 5)"
															:speed="54"
														></uni-notice-bar>
													</view>
													<view class="truncate coupons-box-title" v-else>
														{{ couponItem.subtitile }}
													</view>
												</view>
												
											</view>
											<view class="coupons-box-btns flex flex-align-items-center flex-start relative">
												<!-- status : 0未开启，1可领取，2已领取 -->
												<image class="coupons-btns-item" 
												 @click="setNewerCouponReceiveFun(item)"
												 v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.status === 0"
												 :src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/coupon-receiving-btn.png`"
												 mode=""></image>
												 
												 <image class="coupons-btns-item"
												  @click="setNewerCouponReceiveFun(item)"
												  v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.status === 1"
												  :src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/coupon-receive-btn.png`"
												  mode=""></image>
												  
												  <image class="coupons-btns-item"
												   @click="setNewerCouponReceiveFun(item)"
												   v-if="commonConfigs && commonConfigs.domainFrontFileLink && item.status === 2"
												   :src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/coupon-received-btn.png`"
												   mode=""></image>
											</view>
										</view>
									</view>
								
									<view class="detail-box-reward flex flex-direction-column" v-if="newerPoolWelfareList[currentIdLever] && newerPoolWelfareList[currentIdLever].type !== 1">
										<view class="reward-info-type flex-justify-content-between flex-align-items-center">
											<view class="reward-info-type-list flex flex-direction-column flex-all-center relative"
												v-for="(item, index) in rewardData.type_rate_arr" :key="index">
												<image class="bg"
												:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/level-chance-bg.png`" />
												
												<image v-if="commonConfigs && commonConfigs.domainFrontFileLink"
													:src="commonConfigs.domainFrontFileLink + '/files/images/common/level/level-' + item.reward_item_type.toLowerCase() + '.png'"
													style="height: 26rpx;" mode="heightFix"></image>
													
												<view class="font-hanserif-regular text-nowrap relative">{{ item.rate }}%</view>
											</view>
										</view>
										
										<scroll-view @scrolltolower="scrolltolower" :style="{ height: `calc(100% - 120rpx)` }" scroll-y scroll-with-animation enable-flex>
											<view v-if="resLists && resLists.length">
												<comShopDetail
													senceFrom="newer"
													@gooShopDetailFun="gooShopDetailFun"
													:goodProductList="resLists"
													:isLoading="isLoading"
												></comShopDetail>
												
												<comLoadMore :loading="loading" :showLoadendTxt="showLoadendTxt" class="loadmore-txt"></comLoadMore>
											</view>
											<comEmptyData v-if="resLists && !resLists.length && !isLoading"></comEmptyData>
											<comLoading style="width: 100%; height: 100%" v-if="isLoading"></comLoading>
										</scroll-view>
									</view>
								</view>
							</view>
						</view>
						
						<!-- 页面底部操作按钮 -->
						<view :class="['pool-btns-content', 'flex', 'flex-all-center', 'relative', 'font-hanserif-bold',
							rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] && newerPoolWelfareList[currentIdLever].type !== 1 && rewardData.reward_sheet_range[0].reward_price_status !== 'can' ? 'disable-btn' : '',
						]"
						>
							<image class="bg" 
							v-if="commonConfigs && commonConfigs.domainFrontFileLink"
							:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/operate-btn-area-bg.png`" />
							
							<!-- type 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠 -->
							<view class="reward-all-btn relative"
								 v-if="commonConfigs && commonConfigs.domainFrontFileLink && newerPoolWelfareList[currentIdLever] && newerPoolWelfareList[currentIdLever].type === 1">
								<image
									class="bg"
									:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/coupon-all-receive-btn.png`"
									mode=""></image>
								<view class="absolute reward-all-btn-txt flex-all-center" @click="setNewerCouponReceiveFun({}, 'all')">一键领取</view>
							</view>
							 
							 <view v-else class="reward-pool-btn relative">
								<view class="absolute-center flex flex-direction-column flex-all-center reward-pool-btn-box">
									<view @click="setPreOrderFun" class="absolute reward-pool-btn-price flex-all-center flex-direction-column">
										<image class="bg"
											v-if="commonConfigs && commonConfigs.domainFrontFileLink"
											:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/coupon-all-receive-btn.png`" />
										
										<view 
											:class="['text-nowrap', 'font-hanserif-bold', 'pool-btn-price-maintitle', 'relative', rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] && newerPoolWelfareList[currentIdLever].type !== 1 && rewardData.reward_sheet_range[0].reward_price_status !== 'can' ? 'disable-btn' : '']"
											>{{ rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] ? rewardData.reward_sheet_range[0].reward_price_desc : '-' }}</view>
										<view class="pool-btn-price-subtitle relative">原价：￥{{ rewardData.reward_sheet_range && rewardData.reward_sheet_range[0].reward_price_all }}</view>
									</view>
								</view>
								
								<view class="reward-pool-btn-desc absolute flex flex-all-center"
									v-if="rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] && rewardData.reward_sheet_range[0].reward_sheet"
								>
									<view class="pool-btn-desc-txt relative flex-nowrap flex-justify-content-center">
										<text>（每天0点重置，每人每天可购买</text>
										<text style="color: #FFFFFF;">
											{{ rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] ? rewardData.reward_sheet_range[0].use_reward_sheet : '-' }}
										</text>
										<text> / <text style="color: #FFFFFF;">{{ rewardData.reward_sheet_range && rewardData.reward_sheet_range[0] ? rewardData.reward_sheet_range[0].reward_sheet : '-' }}</text>发）</text>
									</view>
								</view>
							 </view>
						</view>
					</view>
				</view>

				<comPopup v-model="isShowRecordUppop" title="中奖记录" v-if="isShowRecordUppop">
					<view class="pool-record-box margin-auto">
						<scroll-view
							@scrolltolower="secScrolltolower"
							:style="{ height: `calc(100vh - ${parseInt(commonNavHeight)}px - 700rpx)` }"
							enable-flex
							scroll-with-animation
							scroll-y
						>
							<view v-if="secResLists && secResLists.length">
								<view class="pool-record-list relative flex flex-align-items-center flex-justify-content-between" v-for="(item, index) in secResLists" :key="index">
									<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink" 
									:src="`${commonConfigs.domainFrontFileLink}/files/images/infinite/record-list.png`" mode=""></image>
									
									<view class="record-info-detail relative flex flex-align-items-center">
										<image class="record-info-head" :src="item.avatar" mode=""></image>
										<image :src="item.vip_cover" class="absolute record-info-cover" v-if="item.vip_cover"></image>
										<view class="record-info-title">
											<view class="record-info-title-txt truncate">{{ item.nickname }}</view>
											<view class="record-info-title-dates">{{ item.create_time }}</view>
										</view>
									</view>
									
									<view class="record-info-type relative">
										<view class="record-info-type-box flex-end">
											<image
												class="record-info-type-img absolute"
												:src="`${commonConfigs.domainFrontFileLink}/files/images/common/level/level-` + (item.reward_item_type && item.reward_item_type.toLowerCase()) + '.png'"
												mode="heightFix"
											></image>
										</view>
										<view class="record-info-type-name truncate">{{ item.reward_item_name }}</view>
									</view>
								</view>
								
								<comLoadMore :loading="false" :showLoadendTxt="otherShowLoadedText" class="loadmore-txt"></comLoadMore>
							</view>
							<comEmptyData v-else-if="secResLists && !secResLists.length && !secLoading"></comEmptyData>
							<comLoading style="width: 100%; height: 100%" v-if="secLoading"></comLoading>
						</scroll-view>
						
					</view>
				</comPopup>

				<!-- 结果弹窗 -->
				<comMask v-model="isShowResultUppop">
					<view class="award-uppop relative">
						<view class="award-uppop-box relative">
							<image
								v-if="commonConfigs && commonConfigs.domainFrontFileLink"
								:src="`${commonConfigs.domainFrontFileLink}/files/images/common/reward-box-bg.png`"
								class="bg"
								mode=""
							></image>
							<scroll-view :style="{ height: `calc(100% - 20rpx)` }" 
								enable-flex 
								scroll-with-animation
								scroll-y 
							>
								<comRewardList :awardData="awardData" v-if="isShowResultUppop"></comRewardList>
							</scroll-view>
						</view>
						
						<view class="award-uppop-btns flex flex-justify-content-evenly relative">
							<view class="flex flex-all-center relative uppop-btn" @click="gooPageUrl('/secondary/bagPage/bagPage')">
								<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/popup/reward-bag-btn-cancel.png`"  class="bg" mode=""></image>
							</view>
							<view class="flex relative uppop-btn" @click="isShowResultUppop = false">
								<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/popup/reward-btn-back.png`" class="bg" mode=""></image>
							</view>
						</view>
					</view>
				</comMask>

				<!-- 支付弹窗 -->
				<comRewardOrder 
					ref="comRewardOrder"
					v-model="isShowOrderUppop" 
					poolTypeSence="newerSence" 
					:rewardData="rewardData" 
					@setPayOrderFun="setPayOrderFun" 
					@setNextOrderFun="setNextOrderFun"
					@setCurrentPaysFun="setCurrentPaysFun"
					@setAgreeFun="$store.commit('SHOW_AGREEMENT_SET_FUN', true)"></comRewardOrder>
				
			</view>
		</template>
	</comRoot>
</template>

<script>
	import pager from '@/inmixed/paging.mixin.js';
	import otherpay from '@/inmixed/otherpay.mixin.js'
	import secPager from '@/inmixed/secPaging.mixin.js';
	import { payment } from '@/setupproject/PAYS_FUN';
	import { ACTIONS } from '@/store/modules/userStore';
	import store from '@/store';
	import audio from '@/setupproject/AVIDEO_FUN.js';
	import { boxIndexSetFun, wxAuthSetFun, addPhoneSetFun, setAsyncFunWait,
	setDayTimeFunFormat,
	getfilterValueArrayFun, setJsonObjToUrlFun
	} from '@/setupproject/TOOLS_FUN';
	
	import {
		getHomePersonCouponListApi,
		getHomePersonCouponDoneApi,
		getPoolInfiniteItemNewPersonApi,
		getHomePersonPoolNewApi,
		getContentAgreementApi, 
		getContentAgreementDotApi,
		getContentHomeApi,
		getRewardMessageLogApi,
		geRewardPoolInfoApi,
		geRewardPoolItemDetailApi,
		geRewardPoolItemLogApi,
		geRewardOrderPreApi,
		geRewardOrderApi,
		geRewardsApi,
		geRewardPoolSortNumLogApi,
		geRewardShowItemDetailApi,
	} from '@/setupproject/INTERFACE';

	export default {
		name: 'specialOfferZonePage',
		mixins: [pager, otherpay, secPager],
		data() {
			return {
				isShowRecordUppop: false,
				rewardData: {
					type_rate_arr: [],
				},
				submitLoading: false,
				isShowOrderUppop: false,
				isShowResultUppop: false,
				awardData: [],
				
				isLoading: true,
				loading: false,
				
				isSecLoading: true,
				secLoading: false,
				
				countDownTimeTxt: '0天 00:00:00',
				rewardPoolLever: null, // 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠
				rewardPoolBanner: '',
				
				timer: null,
				newerPoolWelfareList: [],
				newerCouponData: [],
				
				optionData: {},
				bulletChatRecordData: [],
				timeLenStr: new Date().getTime(),
				
				currentIdLever: 0,
				poolIdLever: 0,
				poolTypeData: [
					{ type: 1, mainTitle: '白嫖', subTitle: '优惠券' },
					{ type: 2, mainTitle: '初阶', subTitle: '新手池子' },
					{ type: 3, mainTitle: '中阶', subTitle: '新手池子' },
					{ type: 4, mainTitle: '高阶', subTitle: '新手池子' },
					{ type: 5, mainTitle: '特惠', subTitle: '专属池子' },
				],
				
				// 监听返回当前平台时触发支付结果事件
				payBeInfos: {
					isPayBackSence: false,
					isReward: true, // 是否是抽赏：全局赏、飞机赏、
					type: null,
					balance_order_num: null
				},
				apiPayTypeVal: 2,
				currentPayType: 'wxpay',
			};
		},
		computed: {
			commonOnline() {
				return store.getters.commonOnline;
			},
			otherShowLoadedText() {
				return this.isShowSecPageLoadedTxt && !this.secLoading && this.secResLists.length ? true : false;
			},
			boxSubIndex() {
				return store.getters.boxSubIndex;
			},
			showLoadendTxt() {
				return this.isShowPageLoadedTxt && !this.loading && this.resLists.length ? true : false;
			},
			commonNavHeight() {
				return store.getters.commonNavHeight + 'px';
			},
			commonConfigs() {
				return store.getters.commonConfigs || {};
			},
		},
		watch: {
			isShowOrderUppop(v) {
				if (!v) {
					this.submitLoading = false;
				}
			}
		},
		onShareAppMessage(e) {
			let optionData = setJsonObjToUrlFun(this.optionData);
			
			if (e.from === 'menu') {
				this.$store.commit('SHARE_INFO_SET_FUN', {
					title: "新手福利专区",
					path: `/secondary/specialOfferZonePage/specialOfferZonePage?${optionData}`,
					imageUrl: `${this.commonConfigs.domainFrontFileLink}/files/images/common/new-mp-share.png`,
					content: '',
					desc: ''
				});
			}
			
			uni.showLoading({
				title: '',
				mask: false
			});

			const promise = new Promise((resolve) => {
				setTimeout(() => {
					const { shareObjData } = this.$store.getters;

					resolve(shareObjData);

					uni.hideLoading();
				}, 200);
			});

			return {
				promise
			};
		},
		async onLoad(options) {
			uni.showShareMenu({});
			console.log(options.type,'options.type----------------------');
			this.rewardPoolLever = Number(options.type); // 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠
			this.rewardPoolBanner = (options.reward_pool_show_top_cover ? decodeURIComponent(options.reward_pool_show_top_cover) : '');
			this.optionData = options;
			this.poolIdLever = options.id;
			
			// 获取手机号避免抽赏时出现手机号授权弹框
			await this.$store.dispatch(ACTIONS.USER_INFO_GET_FUN);
			
			await this.getNewerPoolFun(true, options);
			
			await setAsyncFunWait(200);
			
			await this.getBulletChatFun();
		},
		onShow() {
			// #ifdef APP-PLUS
			if(this.$store.getters.detailRechargeFlag) {
				uni.$emit('update', 'comRewardOrder');
				
				// 详情页充值标志位
				this.$store.commit('SET_DETAIL_RECHARGE_FLAG', false);
				return;
			}
			// #endif
			
			// 监听返回当前平台时触发支付结果事件
			if(this.payBeInfos.isPayBackSence && ['adapay_mini', 'alipay', 'yeepay_wx', 'adapay_alipay', 'mbpay_jump_mini'].includes(this.currentPayType)){
				this.payBeInfos.isPayBackSence = !this.payBeInfos.isPayBackSence;
				this.$store.commit('SET_WATCH_PLAT_PARAMS', {
					'type': this.payBeInfos.type,
					'balance_order_num': this.payBeInfos.balance_order_num,
					'msg': '已购买成功，请去赏袋查看',
					'isReward': true
				});
			}
		},
		onUnload() {
			if(this.timer) {  
				clearInterval(this.timer);  
				this.timer = null;  
			}  
		},
		methods: {
			async getLastDataFun() {
				await this.getNewerPoolFun();
				// 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠
				if(this.newerPoolWelfareList[this.currentIdLever]?.type === 1) {
					await this.getNewerCouponFun();
				}else{
					await this.geRewardPoolInfoApi();
					await this.getRewardPoolDetailFun();
				}
			},
			
			// 白嫖优惠券活动领取
			async setNewerCouponReceiveFun(item, type) {
				// #ifdef APP-PLUS
				// 支付前验证是否已登录
				if (await this.$store.dispatch('SHOW_LOGIN_APP_GET_FUN')) return;
				// #endif
				
				let params = {
					id: this.newerPoolWelfareList[this.currentIdLever]?.id,
				};
				
				if(type !== 'all') {
					params.sid = item.sid;
				}
			
				const { data, code, msg } = await getHomePersonCouponDoneApi(params);
				
				if (code === 200) {
					uni.showToast({
						icon: 'success',
						title: '领取成功'
					});
				}
				
				setTimeout(async () => {
					await this.getNewerPoolFun();
					if(this.newerPoolWelfareList[this.currentIdLever]?.type !== 1) {
						await this.geRewardPoolInfoApi();
					}else{
						await this.getNewerCouponFun();
					}
				}, 200);
			},
			
			async getNewerCouponFun() {
				const { data, code } = await getHomePersonCouponListApi({
					id: this.newerPoolWelfareList[this.currentIdLever]?.id,
				});
				
				if (code !== 200) return;
			
				this.newerCouponData = data.rows;
			},
			
			getLastBulletChatFun(isReQuestFlag) {
				if (isReQuestFlag) {
					this.bulletChatRecordData = [];
					this.getBulletChatFun();
					this.$forceUpdate();
				}
			},
			
			async getBulletChatFun() {
				const {
					data,
					code
				} = await getRewardMessageLogApi({
					is_new_person: 1,
					reward_pool_id: this.poolIdLever,
				});
				
				if (code !== 200) return;
				
				this.bulletChatRecordData = data.log_message_list || [];
			},
			
			gooShopDetailFun(index) {
				for (var i = 0; i < this.rewardData.type_rate_arr.length; i++) {
					if(this.rewardData.type_rate_arr[i].reward_item_type.toUpperCase() === this.resLists[index].reward_item_type.toUpperCase()) {
						this.resLists[index].reward_rate = this.rewardData.type_rate_arr[i].rate + '%';
						break;
					}
				}
				
				this.$store.commit('GLOBAL_DETAILS_SET_FUN', this.resLists[index]);
				
				uni.navigateTo({
					url: '/secondary/goodDetailPage/goodDetailPage?type=all'
				});
			},
			
			async tabPoolTypeFun(item, index) {
				this.currentIdLever = index;
				
				if(item.type !== 1) {
					await this.geRewardPoolInfoApi();
					await this.getRewardPoolDetailFun();
				}else{
					await this.getNewerCouponFun();
				}
				
				clearInterval(this.timer);
				
				if (item.remain_time) {
					this.countDownTimeTxt = setDayTimeFunFormat(item.remain_time || 0);
					
					this.timer = setInterval(() => {
						if (!item.remain_time) {
							clearInterval(this.timer);
						}
						
						this.countDownTimeTxt = setDayTimeFunFormat(item.remain_time || 0);
						
						item.remain_time--;
					}, 1000);
				}else{
					this.countDownTimeTxt = '已结束';
				}
			},
			
			async getNewerPoolFun(isHavFromPool, options) {
				let listLen = this.newerPoolWelfareList.length;
				
				const { data } = await getHomePersonPoolNewApi({
					scene: 1,
					is_banner: 0,
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
				});
				this.newerPoolWelfareList = data.rows || [];
				
				if(listLen !== this.newerPoolWelfareList.length) {
					this.currentIdLever = 0;
				}
				
				if(isHavFromPool) {
					this.currentIdLever = this.newerPoolWelfareList && this.newerPoolWelfareList.findIndex(item => item.type === this.rewardPoolLever) || 0
				
					if(!this.newerPoolWelfareList || (this.newerPoolWelfareList && !this.newerPoolWelfareList.length)) {
						return;
					}
					
					if(this.newerPoolWelfareList && this.newerPoolWelfareList.length) {
						if(this.newerPoolWelfareList.findIndex(item => item.type === this.rewardPoolLever) === -1) {
							this.rewardPoolLever = this.newerPoolWelfareList[0].type;
						}
					}
					
					if(isHavFromPool) {
						this.currentIdLever = this.newerPoolWelfareList && this.newerPoolWelfareList.findIndex(item => item.type === this.rewardPoolLever) || 0
					}
					
					// 等级类型: 1优惠券，2初阶，3中阶，4高阶，5特惠
					if(Number(options.type) === 1) {
						await this.getNewerCouponFun();
					}else{
						await this.geRewardPoolInfoApi();
						await this.getRewardPoolDetailFun();
					}
					
					clearInterval(this.timer);
					
					if (options.remain_time) {
						this.countDownTimeTxt = setDayTimeFunFormat(options.remain_time || 0);
						
						this.timer = setInterval(() => {
							if (!options.remain_time) {
								clearInterval(this.timer);
							}
							
							this.countDownTimeTxt = setDayTimeFunFormat(options.remain_time || 0);
							
							options.remain_time--;
						}, 1000);
					}else{
						this.countDownTimeTxt = '已结束';
					}
				}
			},
			
			getfilterValueArrayFun(list, key, value) {
			  return getfilterValueArrayFun(
			    list,
			    key,
			    value
			  ) || {};
			},
			
			async geRewardPoolInfoApi() {
				const { data, code } = await getPoolInfiniteItemNewPersonApi({
					reward_pool_id: this.newerPoolWelfareList[this.currentIdLever]?.reward_pool_id,
					reward_cur_box_num: 1,
					is_new_person: 1,
				});
				
				if (code !== 200) return;

				this.rewardData = data;
				
				if(data && data.reward_pool_show_top_cover) {
					this.rewardPoolBanner = data.reward_pool_show_top_cover || '';
				}
			},
			
			async getSecList() {
				this.secLoading = true;
				this.isSecLoading = true;
				
				if (this.isShowRecordUppop) {
					const { data, code } = await geRewardPoolItemLogApi({
						...this.secInfoPageObj,
						reward_pool_id: this.newerPoolWelfareList[this.currentIdLever]?.reward_pool_id,
						reward_cur_box_num: 1,
						is_new_person: 1,
					});
					
					this.secLoading = false;
					
					setTimeout(() => {
						this.isSecLoading = false;
					}, 0);
					
					if (code !== 200) return;
					
					data.secResLists = data.rows;
					
					return data;
				}
			},
			
			async getPoolRecordFun() {
				this.isShowRecordUppop = true;
				/* 方法来自 secPaging.mixin.js */
				this.secPagingInitFun();
				this.GetSecResLists();
			},
			
			async getRewardPoolDetailFun() {
				/* paging.mixin.js Methods */
				this.pagingInitFun();
				this.resListsGetFun();
			},
			
			async listsGetFun() {
				this.loading = true;
				this.isLoading = true;
				
				const { data, code } = await geRewardPoolItemDetailApi({
					...this.pageInfoObj,
					reward_pool_id: this.newerPoolWelfareList[this.currentIdLever]?.reward_pool_id,
					reward_cur_box_num: 1,
					is_new_person: 1,
				});
				
				this.loading = false;
				setTimeout(() => {
					this.isLoading = false;
				}, 0);
				
				if (code !== 200) return;
				
				data.resLists = data.rows;
				
				return data;
			},
			
			orderInfoDats() {
				return {
					reward_pool_id: this.newerPoolWelfareList[this.currentIdLever]?.reward_pool_id,
					use_currency_num: store.getters.commonPaySortList.includes(1) ? 1 : 0,
					reward_num: 1,
					is_new_person: 1,
					pay_channel: this.currentPayType,
					use_balance: store.getters.commonPaySortList.includes(2) ? 1 : 0,
					reward_cur_box_num: 1,
				};
			},
			
			async setPayOrderFun() {
				if (this.submitLoading) return;
				this.submitLoading = true;
			
				const { data: productInfos, code, msg } = await geRewardOrderApi(this.orderInfoDats());

				if (code !== 200) {
					this.submitLoading = false;
					return uni.showToast({
						icon: 'none',
						title: msg
					});
				}
			
				// 原生支付： 微信、小程序、支付宝
				if (['wxapp', 'wxpay', 'alipay_method', 'mbpay_wxmini'].indexOf(this.currentPayType) !== -1) {
					try {
						if (!productInfos.is_need_wx_pay) {
							await this.getRewardResFun(productInfos.order_num);
							return (this.submitLoading = false);
						}
			
						await payment(productInfos, this.currentPayType || 'wxpay', this.apiPayTypeVal);
						
						await this.getRewardResFun(productInfos.order_num);
					} catch (e) {
						this.submitLoading = false;
						console.error(e);
					}
					this.submitLoading = false;
			
					return;
				}
				
				// 第三方小程序微信
				if (['adapay_mini', 'yeepay_wx', 'adapay_alipay', 'lianlianpay', 'mbpay_jump_mini'].includes(this.currentPayType)) {
					try {
						if (!productInfos.is_need_wx_pay) {
							await this.getRewardResFun(productInfos.order_num, msg)
							return this.submitLoading = false;
						}
						
						productInfos.balance_order_num = productInfos.order_num;
						
						return this.launchMPToPayFun(productInfos, this.currentPayType, 'specialOfferZone');
					} catch (e) {
						this.submitLoading = false;
						console.error(e);
					}
					return;
				}
			},
			
			// 订单弹窗-预购买
			async setPreOrderFun() {
				// #ifdef MP-WEIXIN
				// 支付前验证是否已登录
				if (!wxAuthSetFun()) return;
				// #endif
			
				// #ifdef APP-PLUS
				// 支付前验证是否已登录
				if (await store.dispatch('SHOW_LOGIN_APP_GET_FUN')) return;
				// 支付前验证是否已绑定手机
				if (addPhoneSetFun()) return;
				// #endif
				
				if(!this.rewardData.reward_sheet_range[0] || this.rewardData.reward_sheet_range[0].reward_price_status !== 'can') {
					return;
				}
				
				// 限额提醒
				this.getPayNotice();
				
				this.$set(this.rewardData, 'num', 1);
				this.$set(this.rewardData, 'reward_num', 1);
				this.$set(this.rewardData, 'cover', this.rewardData.reward_pool_cover);
				this.$set(this.rewardData, 'name', this.rewardData.reward_pool_name);
				
				this.setNextOrderFun();
			},
			
			
			async getRewardResFun(order_num) {
				const { data, msg, code } = await geRewardsApi({
					order_num
				});
			
				if (code !== 200) {
					this.submitLoading = false;
					return uni.showToast({
						icon: 'none',
						title: msg,
						duration: 2000
					});
				}
			
				this.awardData = [];
				this.isShowOrderUppop = false;
				
				// 是否开启开奖声音
				if(!uni.getStorageSync('isRewardAudioSwitch')) {
					audio.setPlayAVideo(`${this.commonConfigs.domainFrontFileLink}/files/avideo/open-box-audio.mp3`); // 中奖声音
				}
			
				for (let item of data.sort_detail) {
					this.awardData.push(item);
				}
			
				this.isShowResultUppop = true;
				
				await this.getLastDataFun();
				await setAsyncFunWait(800);
				
				uni.showToast({
					icon: 'none',
					title: msg,
					mask: true,
					duration: 500
				});
			
				this.submitLoading = false;
			},
			
			gooPageUrl(url) {
				uni.navigateTo({
					url
				});
			},
			
			async setNextOrderFun() {
				const { data, code } = await geRewardOrderPreApi(this.orderInfoDats());
				
				if (code !== 200) return false;

				if (!data) return;
				
				this.$set(this.rewardData, 'deduct_currency_num_rmb', data.deduct_currency_num_rmb || 0);
				this.$set(this.rewardData, 'allPrice', data.reward_price_final);
				this.$set(this.rewardData, 'price', this.rewardData.reward_price_1);
				this.$set(this.rewardData, 'balance', data.balance);
				this.$set(this.rewardData, 'currency_num', data.currency_num);
				this.$set(this.rewardData, 'is_view_pay_agreement', data.is_view_pay_agreement);
				this.$set(this.rewardData, 'deduct_balance_rmb', data.deduct_balance_rmb || 0);
				this.$set(this.rewardData, 'beforePrice', data.reward_price_before_coupon);
				this.$set(this.rewardData, 'couponResult', data.coupon_resutl);
				
				this.isShowOrderUppop = true;
			},
			
			setCurrentPaysFun(value) {
				this.currentPayType = value;
			},
			
			showNoticeTxtFun(name, len) {
				if (name) {
					var namelen = name.length, sum = 0; 
					for (var i = 0; i < namelen; i++) {
						// 中文: 字符编码大于255
						if (name.charCodeAt(i) > 255) {  
							sum += 2;  // 双字节, 累加2
						} else {
							sum++;  // 单字节, 累加1
						}
					}
					if (sum > len*2) {
						return name;
					}
				}
			},
			
		}
	};
</script>

<style scoped lang="scss">
	.newer-born-zone {
		width: 100vw;
		height: 100vh;
		overflow-x: hidden;
		
		.newer-born-bg {
			width: 100%;
			height: 702rpx;
			left: 0;
		}
		
		.newer-content {
			width: 100%;
			height: 100%;
			
			.newer-content-bg {
				width: 100%;
				height: 424rpx;
			}
			
			.com-bullet-chat {
				width: 100%;
				height: 100rpx;
			}
			
			.newer-content-box {
				width: 100%;
				height: calc(100% - 370rpx);
				bottom: 0rpx;
				// padding: 20rpx;
				
				.countdown-time-view {
					top: -70rpx;
					
					.countdown-time-detail {
						width: 403rpx;
						padding-left: 36rpx;
						font-size: 22rpx;
						color: #FFFFFF;
						height: 56rpx;
						
						.countdown-time-txt {
							margin: 0 6rpx;
						}
						.countdown-time-nums {
							font-size: 22rpx;
							color: #FFFFFF;
						}
					}
					
					.award-entry-icon {
						width: 168rpx;
						height: 68rpx;
						left: 70rpx;
						top: 66rpx;
					}
				}
				
				.pool-type-content {
					margin: 0 auto;
					width: 750rpx;
					height: calc(100% - 315rpx);
					padding: 20rpx 20rpx 0rpx 20rpx;
					
					.pool-type-title {
						width: 230rpx;
						height: 100%;
						overflow-y: auto;
						padding-top: 42rpx;
						padding-left: 10rpx;
						background-size: 100% 100%;
						.pool-type-info {
							margin-bottom: 20rpx;
						}
						
						.pool-type-list {
							width: 218rpx;
							height: 90rpx;
							.info-maintitle {
								color: #FFFFFF;
								font-size: 30rpx;
								// background: linear-gradient(0deg, #FFF 0%, #FFDA4D 100%);
								// -webkit-background-clip: text;
								// -webkit-text-fill-color: transparent;
							}
							.info-subtitle {
								font-size: 24rpx;
								color: #63FFF7;
							}
						}
						
						.info-dates {
							width: 100%;
							height: 30rpx;
							.info-dates-txt {
								font-size: 18rpx;
								color: #FFFFFF;
								background: linear-gradient(0deg, #CCC 0%, #000);
								-webkit-background-clip: text;
								-webkit-text-fill-color: transparent;
							}
						}
						
						.pool-type-info-active {
							color: #FFF;
							text-shadow: 1rpx 1rpx 18rpx blue;
							.info-maintitle {
								background: unset;
								-webkit-background-clip: unset;
								-webkit-text-fill-color: unset;
							}
							.info-subtitle {
								background: unset;
								-webkit-background-clip: unset;
								-webkit-text-fill-color: unset;
							}
						}
					}
					
					.pool-type-detail {
						height: 96%;
						overflow: hidden;
						line-height: 52rpx;
						.pool-type-detail-box {
							width: 100%;
							height: 52rpx;
							color: #FFFFFF;
							
							.detail-box-maintitle {
								top: 18rpx;
								font-size: 30rpx;
								margin-left: 20rpx;
								text-indent: 20rpx;
							}
							.detail-box-subtitle {
								font-size: 26rpx;
								top: 18rpx;
							}
							.detail-box-tiptitle {
								font-size: 20rpx;
								color: #63FFF7;
								height: 32rpx;
								padding-right: 28rpx;
								margin-left: 14rpx;
								
								.uni-notice-bar {
									width: 100%;
								}
							}
						}
						
						.detail-box-info {
							width: 100%;
							height: calc(100% - 50rpx);
							padding: 18rpx 0 0rpx;
							overflow: auto;
							
							.detail-box-info-content {
								width: 451rpx;
								height: 248rpx;
								margin: 44rpx 0rpx;
								.info-detail-title {
									color: #001762;
									margin-left: 18rpx;
									margin-bottom: 28rpx;
									font-size: 26rpx;
									.info-detail-title-txt {
										// width: 284rpx;
										min-width: 284rpx;
										height: 57rpx;
										text-align: center;
									}
								}
								.info-detail-coupons {
									.detail-coupons-box {
										color: #FFFFFF;
										overflow-x: auto;
										padding-right: 30rpx;
										margin-top: 20rpx;
										margin-bottom: 10rpx;
										font-size: 22rpx;
										
										.coupons-box-view {
											margin: 0 0 0 30rpx;
											
											.coupons-box-img {
												width: 110rpx;
												height: 132rpx;
												margin-bottom: 6rpx;
												
												.coupons-box-img-cover {
													height: 132rpx;
												}
											}
											
											.coupons-bar-title {
												height: 38rpx;
												padding: 6rpx 6rpx 0;
											}
											
											.coupons-box-title {
												font-size: 22rpx;
												width: 94rpx;
												height: 38rpx;
												text-align: center;
												color: #111111;
											}
											
										}
										
									}
									.coupons-box-btns {
										.coupons-btns-item {
											width: 168rpx;
											height: 52rpx;
										}
									}
									
								}
							}
						
							.detail-box-reward {
								width: 100%;
								height: 100%;
								margin-top: 20rpx;
								.reward-info-type {
									width: 96%;
									height: 180rpx;
									padding: 0 20rpx;
									margin: 0rpx 0 12rpx;
									overflow-x: auto;
									overflow-y: hidden;
							
									.reward-info-type-list {
										color: #FFFFFF;
										font-size: 20rpx;
										width: 90rpx;
										height: 102rpx;
										flex: 0 0 118rpx;
									}
								}
							}
							
						}
						
					}
				}
				
				.pool-btns-content {
					width: 100%;
					height: 230rpx;
					margin-top: -16rpx;
					&.disable-btn {
						filter: grayscale(90%);
						-webkit-filter: grayscale(90%);
						-moz-filter: grayscale(90%);
						-ms-filter: grayscale(90%);
						-o-filter: grayscale(90%);
					}
					
					.reward-all-btn {
						width: 650rpx;
						height: 96rpx;
						top: -44rpx;
						.reward-all-btn-txt {
							width: 650rpx;
							height: 96rpx;
							font-size: 32rpx;
							font-weight: bold;
							color: #FFFFFF;
						}
					}
					
					.reward-pool-btn {
						width: 100%;
						height: 100%;
						.reward-pool-btn-box {
							width: 650rpx;
							height: 96rpx;
							top: -126rpx;
							
							.reward-pool-btn-price {
								width: 650rpx;
								height: 96rpx;
								// top: -38rpx;
							}
							
							.pool-btn-price-maintitle {
								font-size: 32rpx;
								color: #FFFFFF;
								// text-shadow: 0rpx 4rpx 4rpx rgba(0, 0, 0, 0.7);
								&.disable-btn {
									color: #e0dbd9;
								}
							}
							.pool-btn-price-subtitle {
								font-size: 28rpx;
								font-weight: bold;
								text-decoration: line-through;
								color: #FFFFFF;
							}
						}
						
						.reward-pool-btn-desc {
							width: 100%;
							top: 100rpx;
							
							.pool-btn-desc-bg {
								width: 20rpx;
								height: 16rpx;
							}
							.pool-btn-desc-txt {
								color: #FFFFFF;
								font-size: 26rpx;
							}
						}
					}
					
				}
				
			}
			
		}

	}

	.pool-record-box {
		width: 700rpx;
		.pool-record-list {
			width: 100%;
			padding: 16rpx 22rpx;
			margin-bottom: 18rpx;
			color: #111111;
			.record-info-detail {
				.record-info-head {
					margin-right: 14rpx;
					width: 72rpx;
					height: 72rpx;
					border-radius: 100%;
				}
				.record-info-cover{
					width: 96rpx;
					height: 96rpx;
					top: -10rpx;
					left: -12rpx;
				}
				.record-info-title {
					width: 338rpx;
					margin-left: 20rpx;
					.record-info-title-txt {
						color: #262727; 
						height: 38rpx;
						line-height: 38rpx;
						font-size: 30rpx;
					}
					.record-info-title-dates {
						height: 32rpx;
						line-height: 32rpx;
						font-size: 22rpx;
						color: #666666;
						margin-top: 12rpx;
					}

				}
			}
			.record-info-type {
				width: 210rpx;
				.record-info-type-box {
					.record-info-type-img {
						width: 80rpx;
						height: 56rpx;
					}
				}

				.record-info-type-name {
					color: #FF8B1D;
					text-align: right;
					font-size: 22rpx;
				}
			}
		}
	}

	// 结果弹窗
	.award-uppop {
		font-size: 22rpx;
		color: #111111;
		padding: 0 30rpx;
		
		.award-uppop-box {
			width: 670rpx;
			height: 782rpx;
			padding-top: 80rpx;
		}
		
		.award-uppop-btns {
			height: 70rpx;
			margin-top: 32rpx;
			
			.uppop-btn {
				width: 214rpx;
				height: 70rpx;
			}
		}

	}
</style>
